package com.jvyou.app.ds.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jvyou.app.common.domain.model.PageResult;
import com.jvyou.app.common.utils.orm.WrapperTool;
import com.jvyou.app.ds.domain.dto.FaqCategoryDto;
import com.jvyou.app.ds.domain.entity.FaqCategory;
import com.jvyou.app.ds.mapper.FaqCategoryMapper;
import com.jvyou.app.ds.service.FaqCategoryService;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 驾校问题分类表(FaqCategory)表服务实现类
 *
 * @author 橘柚
 * @since 2025-04-20 12:17:22
 */
@Service("faqCategoryService")
public class FaqCategoryServiceImpl extends ServiceImpl<FaqCategoryMapper, FaqCategory> implements FaqCategoryService {

    private QueryWrapper<FaqCategory> getWrapper(FaqCategoryDto faqCategoryDto) {
        QueryWrapper<FaqCategory> queryWrapper = new QueryWrapper<>();
        WrapperTool.notEmptyLike(queryWrapper, "name", faqCategoryDto.getName());
        queryWrapper.orderByAsc("sort_order");
        return queryWrapper;
    }

    @Override
    public List<FaqCategory> listFaqCategory(FaqCategoryDto faqCategoryDto) {
        return list(getWrapper(faqCategoryDto));
    }

    @Override
    public PageResult<FaqCategory> pageFaqCategory(FaqCategoryDto faqCategoryDto) {
        IPage<FaqCategory> page = new Page<>(faqCategoryDto.getCurrent(), faqCategoryDto.getPageSize());
        page = page(page, getWrapper(faqCategoryDto));
        return PageResult.success(page);
    }
}
